const Router = require('koa-router');
const router = new Router();

// 身份验证
const {authMiddleware} = require('../middlewares/authMiddleware')
// 业务层
const { 
  getUsers,
  getUser,
  createUser,
  updateUser,
  deleteUser,
  deleteUsers,
  loginUser,
  getOpenid,
} = require('../controllers/userController')


// 获取用户列表
router.get('/', authMiddleware, getUsers);

// 获取单个用户
router.get('/:id', authMiddleware, getUser);

// 创建用户
router.post('/', authMiddleware, createUser);

// 更新用户
router.put('/:id', authMiddleware, updateUser);

// 删除用户
router.delete('/:id', authMiddleware, deleteUser);

// 批量删除用户
router.delete('/', authMiddleware, deleteUsers);

// 用户注册
router.post('/register', createUser);

// 用户登录
router.post('/login', loginUser);

// 获取openid
router.post('/openid', getOpenid)

module.exports = router;
